<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item :to="{ path: '/certificatesList' }">证件列表</el-breadcrumb-item>
                <el-breadcrumb-item>{{pageTitle}}</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="table-form-box">
                <h3 class="h3">证件详情</h3>
            
                    <table border="0" width="100%" cellpadding="0" cellspacing="1">
                        <tbody>
                            <tr class="tr-title">
                                <td colspan="6">基本信息</td>
                            </tr>
                            <tr>
                                <td align="right">姓名:</td>
                                <td>{{formData.credentialsUserName}}</td>
                                <td align="right">所属部门:</td>
                                <td>{{formData.departName}}</td>
                                <td align="right"></td>
                                <td></td>
                            </tr>
                            <tr>
                                <td align="right">证件类型:</td>
                                <td>{{formData.credentialsTypeName}}</td>
                                <td align="right">证件编号:</td>
                                <td>{{formData.credentialsNo}}</td>
                                <td align="right"></td>
                                <td></td>
                            </tr>
                            <tr>
                                <td align="right">发证机构:</td>
                                <td>{{formData.credentialsOrganization}}</td>
                                <td align="right">获取证件日期:</td>
                                <td>{{formData.getTime|formatDate}}</td>
                                <td align="right"></td>
                                <td></td>
                            </tr>
                            <tr>
                                <td align="right">生效日期:</td>
                                <td>{{formData.validTime|formatDate}}</td>
                                <td align="right">失效日期:</td>
                                <td>{{formData.invalidTime|formatDate}}</td>

                                <td align="right"></td>
                                <td></td>
                            </tr>
                            <tr>
                                <td align="right">备注:</td>
                                <td colspan="5">{{formData.remarks}}</td>
                            </tr>
                        </tbody>
                    </table>
                <upload-files :files="fileList" @fun="dealFiles" :isShowDel="false" v-if="flag"></upload-files>
            </div>
        </div>
    </div>
</template>

<script>
import appMain from '../../../utils/app_main';
export default {
    name: 'transfer',
    data() {
        return {
            pageTitle: '',
            formData: {
                credentialsNo: '', //证件编号
                credentialsOrganization: '', //认证机构
                credentialsTypeId: '', //证件类型Id   字典查询
                credentialsTypeName: '', //证件类型名称   字典查询
                credentialsTypeValue: '', //证件类型值   字典查询
                credentialsUserId: '', //证件人id
                credentialsUserName: '', //证件人姓名
                departName: '', //部门名称
                departId: '', //部门id
                getTime: '', //获取证件日期
                invalidTime: '', //失效日期
                remarks: '', //备注信息
                validTime: '' //生效日期
            },

            flag: false,
            isEdit: false,

            // 上传文件,选择的文件
            fileList: []
        };
    },
    created() {
        // 如果有id就是跳转过来修改的
        if (this.$route.query.id) {
            this.editId = this.$route.query.id;
            this.isEdit = true;
            this.getData(); // 获取要修改的数据
        } else {
            this.$router.push({
                path: '/certificatesList' //跳转的路径
            });
        }
    },
    methods: {
        getData() {
            appMain
                .credentialsFindById({}, this.editId)
                .then(res => {
                    if (res.data.code === 20000) {
                        this.formData = res.data.data;
                        //获取人员档案附件
                        this.uploadFileInfoFindById(this.formData.id);
                    } else {
                        this.$message.error(res.data.message);
                    }
                })
                .catch(err => {
                    console.log(err);
                });
        },
        //根据id查询附件
        uploadFileInfoFindById(id) {
            appMain
                .uploadFileInfoFindById({}, id)
                .then(res => {
                    if (res.data.code === 20000) {
                        this.fileList = res.data.data;
                        this.flag = true;
                    } else {
                        this.$message.error(res.data.message);
                    }
                })
                .catch(err => {
                    console.log(err);
                });
        },

        // 上传文件返回
        dealFiles(data) {
            this.fileList = data.backData;
            this.formData.uploadReturns = this.fileList;
        }
    },
    mounted() {
        this.pageTitle = this.$router.currentRoute.meta.title;
    },
    filters: {
        //时间过滤器
        formatDate: function(val) {
            let date = new Date(val);
            return appMain.formatDate(date, 'yyyy-MM-dd hh:mm:ss');
        }
    }
};
</script>

<style scoped>
.container {
    padding-bottom: 50px;
}
.handle-box {
    padding: 5px 50px;
    width: 100%;
    background-color: #fff;
    position: absolute;
    left: 0;
    bottom: 0px;
    border-bottom: 1px solid #ddd;
    border-top: 1px solid #ddd;
    z-index: 1;
}

.table {
    width: 100%;
    font-size: 14px;
}

.table-form-box table {
    background-color: #666;
}
.table-form-box .h3 {
    font-size: 22px;
    text-align: center;
    font-weight: normal;
    padding: 20px 0;
}
.table-form-box table .tr-title td {
    font-size: 14px;
    line-height: 40px;
}
.table-form-box table td,
.table-form-box table th {
    background-color: #fff;
    padding: 4px;
    min-height: 40px;
    font-size: 12px;
}
.color-ff2200 {
    color: #ff2200;
}
</style>
